package com.cn.xiaonuo.tcrfinance.tcrshops.controller;

import com.cn.xiaonuo.common.entity.BusinessMessage;
import com.cn.xiaonuo.common.utils.ApiJsonModel;
import com.cn.xiaonuo.core.annotion.BusinessLog;
import com.cn.xiaonuo.core.enums.LogAnnotionOpTypeEnum;
import com.cn.xiaonuo.core.pojo.response.ResponseData;
import com.cn.xiaonuo.core.pojo.response.SuccessResponseData;
import com.cn.xiaonuo.tcrfinance.tcrshops.param.PvProductTypeParam;
import com.cn.xiaonuo.tcrfinance.tcrshops.service.ProductTypeService;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
/**
 * banner图
 * @author Mark sunlightcs@gmail.com
 */
@RestController
public class ProductTypeController {


    @Autowired
    private ProductTypeService productTypeService;


    /**
     * 查询免税商品类型列表
     */
    @ApiJsonModel({
            @ApiModelProperty(name = "name", value = "商品类型名称",example = "商品类型名称"),
    })
    @PostMapping("/api/productType/queryProductTypes")
    public BusinessMessage queryProductTypes(String name){

        return productTypeService.queryProductTypeList(name);
    }


    /**
     * 查询商品类别
     *
     * @author luyangyang
     * @date 2021-10-21 16:14:37
     */
    //@Permission
    /**
     * 查询免税商品类型列表
     */
    @ApiJsonModel({
            @ApiModelProperty(name = "name", value = "商品类型名称",example = "商品类型名称"),
    })
    @PostMapping("/api/productType/page")
    @BusinessLog(title = "商品类别_查询", opType = LogAnnotionOpTypeEnum.QUERY)
    @ApiOperation(value = "商品类别_查询", notes = "商品类别_查询")
    public ResponseData page(PvProductTypeParam productTypeParam) {
        productTypeParam.setParentId(1000);
        return new SuccessResponseData(productTypeService.page(productTypeParam));
    }
    /**
     * 添加商品类别
     *
     * @author luyangyang
     * @date 2021-10-21 16:14:37
     */
    //@Permission
    @PostMapping("/api/productType/add")
    @BusinessLog(title = "商品类别_增加", opType = LogAnnotionOpTypeEnum.ADD)
    @ApiOperation(value = "商品类别_增加", notes = "商品类别_增加")
    public ResponseData add(@RequestBody @Validated(PvProductTypeParam.add.class) PvProductTypeParam productTypeParam) {
        SuccessResponseData responseData= new SuccessResponseData();
        productTypeParam.setShowState(1);
        productTypeParam.setParentId(1000);
        if(StringUtils.isBlank(productTypeParam.getName())){
            responseData.setSuccess(false);
            responseData.setCode(1);
            responseData.setMessage("类型名称不能为空");
            return responseData;
        }
        if(StringUtils.isBlank(productTypeParam.getImageUrl())){
            responseData.setSuccess(false);
            responseData.setCode(1);
            responseData.setMessage("类型图片不能为空");
            return responseData;
        }
        productTypeService.add(productTypeParam);
        return new SuccessResponseData();
    }

    /**
     * 删除商品类别
     *
     * @author luyangyang
     * @date 2021-10-21 16:14:37
     */
    // @Permission
    @PostMapping("/api/common/productType/delete")
    @BusinessLog(title = "商品类别_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    @ApiOperation(value = "商品类别_删除", notes = "商品类别_删除")
    public ResponseData delete(@RequestBody @Validated(PvProductTypeParam.delete.class) PvProductTypeParam productTypeParam) {
        productTypeService.delete(productTypeParam);
        return new SuccessResponseData();
    }

    /**
     * 编辑商品类别
     *
     * @author luyangyang
     * @date 2021-10-21 16:14:37
     */
    //@Permission
    @PostMapping("/api/productType/edit")
    @BusinessLog(title = "商品类别_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    @ApiOperation(value = "商品类别_编辑", notes = "商品类别_编辑")
    public ResponseData edit(@RequestBody @Validated(PvProductTypeParam.edit.class) PvProductTypeParam productTypeParam) {
        SuccessResponseData responseData= new SuccessResponseData();
        if(StringUtils.isBlank(productTypeParam.getName())){
            responseData.setSuccess(false);
            responseData.setCode(1);
            responseData.setMessage("类型名称不能为空");
            return responseData;
        }
        if(StringUtils.isBlank(productTypeParam.getImageUrl())){
            responseData.setSuccess(false);
            responseData.setCode(1);
            responseData.setMessage("类型图片不能为空");
            return responseData;
        }
        productTypeService.edit(productTypeParam);
        return new SuccessResponseData();
    }

    /**
     * 查看商品类别
     *
     * @author luyangyang
     * @date 2021-10-21 16:14:37
     */
    //@Permission
    @PostMapping("/api/productType/detail")
    @ApiJsonModel({
            @ApiModelProperty(name = "id", value = "商品类别id",example = "商品类别id",required = true),
    })
    @ApiOperation(value = "商品类别_查看", notes = "商品类别_查看")
    public ResponseData detail(@RequestBody PvProductTypeParam productTypeParam) {
        return new SuccessResponseData(productTypeService.detail(productTypeParam));
    }

    /**
     * 禁用商品分类
     * @param productTypeParam
     * @return
     */
    @ApiJsonModel({
            @ApiModelProperty(name = "id", value = "商品类型id",example = "商品类型id"),
            @ApiModelProperty(name = "showState", value = "状态",example = "状态"),
    })
    @ApiOperation(value = "商品类别_启用/禁用", notes = "商品类别_启用/禁用")
    @PostMapping("/api/productType/updateStatus")
    public ResponseData updateStatus(@RequestBody PvProductTypeParam productTypeParam){
       productTypeService.updateStatus(productTypeParam);
        return new SuccessResponseData();
    }

}
